package com.lyn.serialPort;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

public class Driver {
    public String name;
    public String root;

    public Driver(String name, String root) {
        this.name = name;
        this.root = root;
    }

    public List<File> getDevices() {
        List<File> devices = new ArrayList<>();
        File dev = new File("/dev");
        if (!dev.exists()) {
            return devices;
        } else if (!dev.canRead()) {
            return devices;
        } else {
            File[] files = dev.listFiles();
            if (files != null) {
                for (File file : files) {
                    if (file.getAbsolutePath().startsWith(this.root)) {
                        devices.add(file);
                    }
                }
            }
            return devices;
        }
    }
}
